home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / streaming / qtstreamsplicer / application files / comapplication.c next >
Encoding:
Text File  |  2000-06-23  |  10.2 KB  |  410 lines

  1. //////////
  2. //
  3. //    File:        ComApplication.c
  4. //
  5. //    Contains:    Application-specific code for basic QuickTime movie display and control.
  6. //                This file is used for BOTH MacOS and Windows.
  7. //
  8. //    Written by:    Tim Monroe
  9. //                Based (heavily!) on the MovieShell code written by Apple DTS.
  10. //
  11. //    Copyright:    © 1994-1998 by Apple Computer, Inc., all rights reserved.
  12. //
  13. //    Change History (most recent first):
  14. //
  15. //       <11>         12/16/98    rtm        removed all QTVR API calls, so we can remove QTVR.lib from project
  16. //       <10>         10/23/97    rtm        moved InitializeQTVR to InitApplication, TerminateQTVR to StopApplication
  17. //       <9>         10/13/97    rtm        reworked HandleApplicationMenu to use menu identifiers
  18. //       <8>         09/11/97    rtm        merged MacApplication.c and WinApplication.c into ComApplication.c
  19. //       <7>         08/21/97    rtm        first file for Windows; based on MacApplication.c for Mac sample code
  20. //       <6>         06/04/97    rtm        removed call to QTVRUtils_IsQTVRMovie in InitApplicationWindowObject
  21. //       <5>         02/06/97    rtm        fixed window resizing code
  22. //       <4>         12/05/96    rtm        added hooks into MacFramework.c: StopApplication, InitApplicationWindowObject
  23. //       <3>         12/02/96    rtm        added cursor updating to DoIdle
  24. //       <2>         11/27/96    rtm        conversion to personal coding style; added preliminary QTVR support
  25. //       <1>         12/21/94    khs        first file
  26. //       
  27. //
  28. //    QTShell is a simple QuickTime viewer framework. It demonstrates how to incorporate 
  29. //    QuickTime and QuickTime VR movies into an application. QTShell is based heavily on the 
  30. //    MovieShell QuickTime playback framework included with the DTS QT sample code.
  31. //
  32. //////////
  33.  
  34. // header files
  35. #include "ComApplication.h"
  36. #include "QTStreamSplicer.h"
  37.   
  38. // global variables for Macintosh code
  39. #if TARGET_OS_MAC
  40. #endif
  41.  
  42. // global variables for Windows code
  43. #if TARGET_OS_WIN32
  44. extern HWND                ghWnd;                                    // the MDI frame window; this window has the menu bar
  45. extern int                gNumWindowsOpen;
  46. extern LPSTR            gCmdLine;
  47. #endif
  48.  
  49. long                    gMaxMilliSecToUse = 0L;
  50.  
  51.  
  52. //////////
  53. //
  54. // InitApplication
  55. // Do any application-specific initialization.
  56. //
  57. // The theStartPhase parameter determines which "phase" of application start-up is executed,
  58. // *before* the MDI frame window is created or *after*. This distinction is relevant only on
  59. // Windows, so on MacOS, you should always use kInitAppPhase_BothPhases.
  60. //
  61. //////////
  62.  
  63. void InitApplication (UInt32 theStartPhase)
  64. {
  65.     // ***do any start-up activities that should occur before the MDI frame window is created
  66.     if (theStartPhase & kInitAppPhase_BeforeCreateFrameWindow) {
  67.  
  68.     }    // end of kInitAppPhase_BeforeCreateFrameWindow
  69.  
  70.     // ***do any start-up activities that should occur after the MDI frame window is created
  71.     if (theStartPhase & kInitAppPhase_AfterCreateFrameWindow) {
  72. #if TARGET_OS_WIN32
  73.         // On Windows, open as movie documents any files specified on the command line
  74.         SendMessage(ghWnd, WM_OPENDROPPEDFILES, 0L, 0L);
  75. #endif
  76.     }    // end of kInitAppPhase_AfterCreateFrameWindow
  77. }
  78.  
  79.  
  80. //////////
  81. //
  82. // StopApplication
  83. // Do any application-specific shut-down.
  84. //
  85. // The theStopPhase parameter determines which "phase" of application shut-down is executed,
  86. // *before* any open movie windows are destroyed or *after*.
  87. //
  88. //////////
  89.  
  90. void StopApplication (UInt32 theStopPhase)
  91. {
  92.     // @@@INSERT APPLICATION-SPECIFIC SHUT-DOWN FUNCTIONALITY HERE
  93.     
  94.     // do any shut-down activities that should occur after the movie windows are destroyed
  95.     if (theStopPhase & kStopAppPhase_AfterDestroyWindows) {
  96.         
  97.     }    // end of kStopAppPhase_AfterDestroyWindows
  98. }
  99.  
  100.  
  101. //////////
  102. //
  103. // DoIdle
  104. // Do any processing that can/should occur at idle time.
  105. //
  106. //////////
  107.  
  108. void DoIdle (WindowReference theWindow)
  109. {
  110.     WindowObject         myWindowObject = NULL;
  111.     GrafPtr             mySavedPort;
  112.     
  113.     GetPort(&mySavedPort);
  114.     MacSetPort(GetPortFromWindowReference(theWindow));
  115.     
  116.     myWindowObject = GetWindowObjectFromWindow(theWindow);
  117.     if (myWindowObject != NULL) {
  118.         MovieController        myMC = NULL;
  119.     
  120.         myMC = (**myWindowObject).fController;
  121.         if (myMC != NULL) {
  122.  
  123. #if TARGET_OS_MAC
  124.             // restore the cursor to the arrow
  125.             // if it's outside the front movie window or outside the window's visible region
  126.             if (theWindow == GetFrontMovieWindow()) {
  127.                 Rect    myRect;
  128.                 Point    myPoint;
  129.                 
  130.                 GetMouse(&myPoint);
  131.                 MCGetControllerBoundsRect(myMC, &myRect);
  132.                 if (!MacPtInRect(myPoint, &myRect) || !PtInRgn(myPoint, GetPortFromWindowReference(theWindow)->visRgn))
  133.                     MacSetCursor(&qd.arrow);
  134.             }
  135. #endif    // TARGET_OS_MAC
  136.         }
  137.     }
  138.     
  139.     // @@@INSERT APPLICATION-SPECIFIC IDLE-TIME FUNCTIONALITY HERE
  140.     
  141.     MacSetPort(mySavedPort);
  142. }
  143.  
  144.  
  145. //////////
  146. //
  147. // DoUpdateWindow
  148. // Update the specified window.
  149. //
  150. //////////
  151.  
  152. void DoUpdateWindow (WindowReference theWindow, Rect *theRefreshArea)
  153. {
  154. #pragma unused(theRefreshArea)
  155.  
  156.     GrafPtr             mySavedPort;
  157.     
  158.     GetPort(&mySavedPort);
  159.     MacSetPort(GetPortFromWindowReference(theWindow));
  160.     
  161.     BeginUpdate(GetPortFromWindowReference(theWindow));
  162.     //EraseRect(theRefreshArea);        // this is important, for non-rectangular movies
  163.     
  164.     // @@@INSERT APPLICATION-SPECIFIC DRAWING FUNCTIONALITY HERE
  165.     
  166.     // draw the movie controller and its movie
  167.     MCDoAction(GetMCFromWindow(theWindow), mcActionDraw, theWindow);
  168.     
  169.     EndUpdate(GetPortFromWindowReference(theWindow));
  170.     MacSetPort(mySavedPort);
  171. }
  172.  
  173.  
  174. //////////
  175. //
  176. // HandleContentClick
  177. // Handle mouse button clicks in the specified window.
  178. //
  179. //////////
  180.  
  181. void HandleContentClick (WindowReference theWindow, EventRecord *theEvent)
  182. {
  183. #pragma unused(theEvent)
  184.  
  185.     GrafPtr             mySavedPort;
  186.     
  187.     GetPort(&mySavedPort);
  188.     MacSetPort(GetPortFromWindowReference(theWindow));
  189.     
  190.     // @@@INSERT APPLICATION-SPECIFIC CONTENT CLICKING FUNCTIONALITY HERE
  191.  
  192.     MacSetPort(mySavedPort);
  193. }
  194.  
  195.  
  196. //////////
  197. //
  198. // HandleApplicationKeyPress
  199. // Handle application-specific key presses.
  200. // Returns true if the key press was handled, false otherwise.
  201. //
  202. //////////
  203.  
  204. Boolean HandleApplicationKeyPress (char theCharCode)
  205. {
  206.     Boolean        isHandled = true;
  207.     
  208.     switch (theCharCode) {
  209.     
  210.         // @@@HANDLE APPLICATION-SPECIFIC KEY PRESSES HERE
  211.  
  212.         default:
  213.             isHandled = false;
  214.             break;
  215.     }
  216.  
  217.     return(isHandled);
  218. }
  219.  
  220.  
  221. #if TARGET_OS_MAC
  222. //////////
  223. //
  224. // CreateMovieWindow
  225. // Create a window to display a movie in.
  226. //
  227. //////////
  228.  
  229. WindowRef CreateMovieWindow (Rect *theRect, Str255 theTitle)
  230. {
  231.     WindowRef            myWindow;
  232.     
  233.     myWindow = NewCWindow(NULL, theRect, theTitle, false, noGrowDocProc, (WindowPtr)-1L, true, 0);
  234.     return(myWindow);
  235. }
  236. #endif
  237.  
  238.  
  239. //////////
  240. //
  241. // HandleApplicationMenu
  242. // Handle selections in the application's menus.
  243. //
  244. // The theMenuItem parameter is a UInt16 version of the Windows "menu item identifier". 
  245. // When called from Windows, theMenuItem is simply the menu item identifier passed to the window proc.
  246. // When called from MacOS, theMenuItem is constructed like this:
  247. //     *high-order 8 bits == the Macintosh menu ID (1 thru 256)
  248. //     *low-order 8 bits == the Macintosh menu item (sequential from 1 to ordinal of last menu item in menu)
  249. // In this way, we can simplify the menu-handling code. There are, however, some limitations,
  250. // mainly that the menu item identifiers on Windows must be derived from the Mac values. 
  251. //
  252. //////////
  253.  
  254. void HandleApplicationMenu (UInt16 theMenuItem)
  255. {
  256.     switch (theMenuItem) {
  257.         case IDM_SPLICEIMAGE_ONTOSTREAM:
  258.             QTSplicer_SpliceImageOntoStream();
  259.             break;
  260.  
  261.         case IDM_SPLICEIMAGE_OVERSTREAM:
  262.             QTSplicer_SpliceImageOverStream();
  263.             break;
  264.  
  265.         default:
  266.             break;
  267.     }    // switch (theMenuItem)
  268. }
  269.  
  270.  
  271. //////////
  272. //
  273. // AdjustApplicationMenus
  274. // Adjust state of items in the application's menus.
  275. //
  276. // Currently, the Mac application has only one app-specific menu ("Test"); you could change that.
  277. //
  278. //////////
  279.  
  280. void AdjustApplicationMenus (WindowReference theWindow, MenuReference theMenu)
  281. {
  282.     WindowObject        myWindowObject = NULL; 
  283.     MovieController     myMC = NULL;
  284.     MenuReference        myMenu;
  285.     
  286. #if TARGET_OS_WIN32
  287.     myMenu = theMenu;
  288. #elif TARGET_OS_MAC
  289.     myMenu = GetMenuHandle(kTestMenu);
  290. #endif
  291.     
  292.     SetMenuItemState(myMenu, IDM_SPLICEIMAGE_ONTOSTREAM, kEnableMenuItem);
  293.     SetMenuItemState(myMenu, IDM_SPLICEIMAGE_OVERSTREAM, kEnableMenuItem);
  294. }
  295.  
  296.  
  297. //////////
  298. //
  299. // DoApplicationEventLoopAction
  300. // Perform any application-specific event loop actions.
  301. //
  302. // Return true to indicate that we've completely handled the event here, false otherwise.
  303. //
  304. //////////
  305.  
  306. Boolean DoApplicationEventLoopAction (EventRecord *theEvent)
  307. {
  308. #pragma unused(theEvent)
  309.     
  310.     return(false);            // no-op for now
  311. }
  312.  
  313.  
  314. //////////
  315. //
  316. // AddControllerFunctionality
  317. // Configure the movie controller.
  318. //
  319. //////////
  320.  
  321. void AddControllerFunctionality (MovieController theMC)
  322. {
  323.     long            myControllerFlags;
  324.     
  325.     // CLUT table use
  326.     MCDoAction(theMC, mcActionGetFlags, &myControllerFlags);
  327.     MCDoAction(theMC, mcActionSetFlags, (void *)(myControllerFlags | mcFlagsUseWindowPalette));
  328.  
  329.     // enable keyboard event handling
  330.     MCDoAction(theMC, mcActionSetKeysEnabled, (void *)true);
  331.     
  332.     // disable drag support
  333.     MCDoAction(theMC, mcActionSetDragEnabled, (void *)false);
  334. }
  335.  
  336.  
  337. //////////
  338. //
  339. // InitApplicationWindowObject
  340. // Do any application-specific initialization of the window object.
  341. //
  342. //////////
  343.  
  344. void InitApplicationWindowObject (WindowObject theWindowObject)
  345. {
  346. #pragma unused(theWindowObject)
  347.  
  348.     // @@@INSERT APPLICATION-SPECIFIC WINDOW OBJECT START-UP HERE
  349. }
  350.  
  351.  
  352. //////////
  353. //
  354. // RemoveApplicationWindowObject
  355. // Do any application-specific clean-up of the window object.
  356. //
  357. //////////
  358.  
  359. void RemoveApplicationWindowObject (WindowObject theWindowObject)
  360. {
  361. #pragma unused(theWindowObject)
  362.     
  363.     // @@@INSERT APPLICATION-SPECIFIC WINDOW OBJECT CLEAN-UP HERE
  364.  
  365.     // DoDestroyMovieWindow in MacFramework.c or MovieWndProc in WinFramework.c
  366.     // releases the window object itself
  367. }
  368.  
  369.  
  370. //////////
  371. //
  372. // ApplicationMCActionFilterProc 
  373. // Intercept some mc actions for the movie controller.
  374. //
  375. // NOTE: The theRefCon parameter is a handle to a window object record.
  376. //
  377. //////////
  378.  
  379. PASCAL_RTN Boolean ApplicationMCActionFilterProc (MovieController theMC, short theAction, void *theParams, long theRefCon)
  380. {
  381. #pragma unused(theMC, theParams)
  382.  
  383.     Boolean                isHandled = false;            // false => allow controller to process the action
  384.     WindowObject        myWindowObject = NULL;
  385.     
  386.     myWindowObject = (WindowObject)theRefCon;
  387.     if (myWindowObject == NULL)
  388.         return(isHandled);
  389.         
  390.     switch (theAction) {
  391.     
  392.         // handle window resizing
  393.         case mcActionControllerSizeChanged:
  394.             SizeWindowToMovie(myWindowObject);
  395.             break;
  396.  
  397.         // handle idle events
  398.         case mcActionIdle:
  399.             DoIdle((**myWindowObject).fWindow);
  400.             break;
  401.             
  402.         default:
  403.             break;
  404.             
  405.     }    // switch (theAction)
  406.     
  407.     return(isHandled);    
  408. }
  409.  
  410.